package com.xinxing.learning.batch.increment.listener;

import com.xinxing.learning.batch.common.SyncConstants;
import com.xinxing.learning.batch.mapper.target.TargetUserMapper;
import com.xinxing.learning.batch.service.CdcTempService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.listener.JobExecutionListenerSupport;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@Slf4j
public class IncrementJobEndListener extends JobExecutionListenerSupport {
    @Autowired
    private TargetUserMapper targetUserMapper;

    @Autowired
    private CdcTempService cdcTempService;

    @Override
    public void afterJob(JobExecution jobExecution) {
        BatchStatus status = jobExecution.getStatus();
        Date latestDate = targetUserMapper.selectMaxUpdateTime();
        cdcTempService.updateCdcTempAfterJod(SyncConstants.CDC_TEMP_ID_USER, status, latestDate);
    }
}
